package com.adcc.ags.utility.mq.transfer;

import com.adcc.ags.utility.mq.configuration.MQConfiguration;
import com.adcc.ags.utility.mq.entity.AsyncReceiverState;
import com.ibm.mq.MQQueueManager;

import java.util.concurrent.ExecutorService;

/**
 * 异步接收处理类
 */
public abstract class AsyncReceiver {

    // MQConfiguration
    protected MQConfiguration configuration;

    // 名称
    protected String name;

    // QueueManager(用于长连接QM)
    protected MQQueueManager mqm;

    // 状态
    protected AsyncReceiverState state = AsyncReceiverState.Closed;

    // 线程池对象
    protected ExecutorService executorService;

    // 队列异步接收监听器
    protected AsyncMsgListener listener;

    /**
     * 构造函数
     */
    public AsyncReceiver(){

    }

    /**
     * 构造函数
     * @param configuration
     * @param name
     */
    public AsyncReceiver(MQConfiguration configuration, String name){
        this.configuration = configuration;
        this.name = name;
    }

    /**
     * 构造函数
     * @param name
     * @param mqm
     * @param listener
     */
    public AsyncReceiver(String name,MQQueueManager mqm,AsyncMsgListener listener){
        this.name = name;
        this.mqm = mqm;
        this.listener = listener;
    }

    public String getName(){
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setMqm(MQQueueManager mqm) {
        this.mqm = mqm;
    }

    public void setListener(AsyncMsgListener listener){
        this.listener = listener;
    }

    /**
     *打开方法
     */
    public abstract void open();

    /**
     * 关闭方法
     */
    public abstract void close();
}
